package airport.user.action;

import javax.servlet.http.Cookie; 
import javax.servlet.http.HttpServletResponse;  
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import airport.user.dao.UserDAO;

import com.opensymphony.xwork2.ActionSupport;

//update profile
public class UpdateProfileAction extends ActionSupport implements ServletResponseAware, ServletRequestAware {
	
	private static final long serialVersionUID = 1L;
	private String age = null;
	private String gender = null;
	private String occupation = null;
	private String travelReason = null;
	
	protected HttpServletResponse servletResponse;  
	@Override   
	public void setServletResponse(HttpServletResponse servletResponse) {   
		this.servletResponse = servletResponse;   
	}   
	
	protected HttpServletRequest servletRequest;   
	@Override   
	public void setServletRequest(HttpServletRequest servletRequest) {   
		this.servletRequest = servletRequest;   
	} 
	

	public String execute() {
		String userName = null;
		Cookie[] cookies = servletRequest.getCookies();
		String cookieName = "AirportUser";
		if (cookies != null) {
			for (int i = 0; i < cookies.length; i++) {
				if (cookies[i].getName().equals(cookieName)) {
					userName = cookies[i].getValue();
					break;
				}
			}
		}
		if (gender!=null||age != null||occupation!=null||travelReason!=null) {
			UserDAO dao = new UserDAO();
			dao.updateProfile(gender, occupation, travelReason, age, userName);
		}
		
		return "success";
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getOccupation() {
		return occupation;
	}

	public void setOccupation(String occupation) {
		this.occupation = occupation;
	}

	public String getTravelReason() {
		return travelReason;
	}

	public void setTravelReason(String travelReason) {
		this.travelReason = travelReason;
	}
	
	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}


}
